
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Spring · 书名</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="作者">
        <meta name="identifier" content="图书编号" scheme="ISBN">
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-intopic-toc/style.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-flexible-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    书名
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Books</li>
        
        
    
        <li class="chapter " data-level="2.1" >
            
                <span>
            
                    
                    Java
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1.1" data-path="../java/001环境变量.html">
            
                <a href="../java/001环境变量.html">
            
                    
                    001环境变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.2" data-path="../java/002Java初体验.html">
            
                <a href="../java/002Java初体验.html">
            
                    
                    002Java初体验
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.3" data-path="../java/003变量命名及数据类型.html">
            
                <a href="../java/003变量命名及数据类型.html">
            
                    
                    003变量命名及数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.4" data-path="../java/004运算符.html">
            
                <a href="../java/004运算符.html">
            
                    
                    004运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.5" data-path="../java/005选择结构.html">
            
                <a href="../java/005选择结构.html">
            
                    
                    005选择结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.6" data-path="../java/006循环结构.html">
            
                <a href="../java/006循环结构.html">
            
                    
                    006循环结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.7" data-path="../java/007数组.html">
            
                <a href="../java/007数组.html">
            
                    
                    007数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.8" data-path="../java/008类和对象方法.html">
            
                <a href="../java/008类和对象方法.html">
            
                    
                    008类和对象方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.9" data-path="../java/009构造方法.html">
            
                <a href="../java/009构造方法.html">
            
                    
                    009构造方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.10" data-path="../java/010封装与关键字static.html">
            
                <a href="../java/010封装与关键字static.html">
            
                    
                    010封装与关键字Static
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.11" data-path="../java/011 继承.html">
            
                <a href="../java/011 继承.html">
            
                    
                    011 继承
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.12" data-path="../java/012方法重写.html">
            
                <a href="../java/012方法重写.html">
            
                    
                    012方法重写
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.13" data-path="../java/013多态.html">
            
                <a href="../java/013多态.html">
            
                    
                    013多态
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.14" data-path="../java/014抽象类抽象方法.html">
            
                <a href="../java/014抽象类抽象方法.html">
            
                    
                    014抽象类抽象方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.15" data-path="../java/015接口.html">
            
                <a href="../java/015接口.html">
            
                    
                    015接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.16" data-path="../java/016异常.html">
            
                <a href="../java/016异常.html">
            
                    
                    016异常
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.17" data-path="../java/017集合.html">
            
                <a href="../java/017集合.html">
            
                    
                    017集合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.18" data-path="../java/017集合2.html">
            
                <a href="../java/017集合2.html">
            
                    
                    017集合2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.19" data-path="../java/018泛型.html">
            
                <a href="../java/018泛型.html">
            
                    
                    018泛型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.20" data-path="../java/019Collections算法类.html">
            
                <a href="../java/019Collections算法类.html">
            
                    
                    019Collections算法类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.21" data-path="../java/020枚举.html">
            
                <a href="../java/020枚举.html">
            
                    
                    020枚举
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.22" data-path="../java/021包装类.html">
            
                <a href="../java/021包装类.html">
            
                    
                    021包装类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.23" data-path="../java/022常用类.html">
            
                <a href="../java/022常用类.html">
            
                    
                    022常用类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.24" data-path="../java/023File类.html">
            
                <a href="../java/023File类.html">
            
                    
                    023File类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.25" data-path="../java/024IO流.html">
            
                <a href="../java/024IO流.html">
            
                    
                    024IO流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.26" data-path="../java/025多线程.html">
            
                <a href="../java/025多线程.html">
            
                    
                    025多线程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.27" data-path="../java/025多线程线程池.html">
            
                <a href="../java/025多线程线程池.html">
            
                    
                    025多线程线程池
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.28" data-path="../java/026网络编程Socket.html">
            
                <a href="../java/026网络编程Socket.html">
            
                    
                    026网络编程Socket
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.29" data-path="../java/027XML解析.html">
            
                <a href="../java/027XML解析.html">
            
                    
                    027XML解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.30" data-path="../java/028 注解.html">
            
                <a href="../java/028 注解.html">
            
                    
                    028 注解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.31" data-path="../java/029 Lambda表达式.html">
            
                <a href="../java/029 Lambda表达式.html">
            
                    
                    029 Lambda表达式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.32" data-path="../java/029 反射.html">
            
                <a href="../java/029 反射.html">
            
                    
                    029 反射
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.2" >
            
                <span>
            
                    
                    Mybatis
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.2.1" data-path="../mybatis/MyBatis.html">
            
                <a href="../mybatis/MyBatis.html">
            
                    
                    MyBatis
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.2.1.1" >
            
                <span>
            
                    
                    MyBatis
            
                </span>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.3" >
            
                <span>
            
                    
                    Mysql
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.3.1" data-path="../mysql/01 SQL通用语法.html">
            
                <a href="../mysql/01 SQL通用语法.html">
            
                    
                    01 SQL通用语法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.2" data-path="../mysql/02 DDL.html">
            
                <a href="../mysql/02 DDL.html">
            
                    
                    02 DDL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.3" data-path="../mysql/03 DML.html">
            
                <a href="../mysql/03 DML.html">
            
                    
                    03 DML
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.4" data-path="../mysql/04 DQL.html">
            
                <a href="../mysql/04 DQL.html">
            
                    
                    04 DQL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.5" data-path="../mysql/05 DCL.html">
            
                <a href="../mysql/05 DCL.html">
            
                    
                    05 DCL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.6" data-path="../mysql/06 函数.html">
            
                <a href="../mysql/06 函数.html">
            
                    
                    06 函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.7" data-path="../mysql/07 约束.html">
            
                <a href="../mysql/07 约束.html">
            
                    
                    07 约束
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.8" data-path="../mysql/08 多表查询.html">
            
                <a href="../mysql/08 多表查询.html">
            
                    
                    08 多表查询
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.9" data-path="../mysql/09 事务.html">
            
                <a href="../mysql/09 事务.html">
            
                    
                    09 事务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.10" data-path="../mysql/999zzz.html">
            
                <a href="../mysql/999zzz.html">
            
                    
                    999zzz
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.11" data-path="../mysql/MySql.html">
            
                <a href="../mysql/MySql.html">
            
                    
                    MySql
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.12" data-path="../mysql/sql.html">
            
                <a href="../mysql/sql.html">
            
                    
                    Sql
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.4" >
            
                <span>
            
                    
                    Spring
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="2.4.1" data-path="spring.html">
            
                <a href="spring.html">
            
                    
                    Spring
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.5" >
            
                <span>
            
                    
                    SpringMVC
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.5.1" data-path="../springMVC/springMVC.html">
            
                <a href="../springMVC/springMVC.html">
            
                    
                    SpringMVC
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.6" >
            
                <span>
            
                    
                    整合
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.6.1" data-path="../整合/Mybatis框架.html">
            
                <a href="../整合/Mybatis框架.html">
            
                    
                    Mybatis框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.2" data-path="../整合/SpringBoot.html">
            
                <a href="../整合/SpringBoot.html">
            
                    
                    SpringBoot
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.3" data-path="../整合/springmvc框架.html">
            
                <a href="../整合/springmvc框架.html">
            
                    
                    Springmvc框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.4" data-path="../整合/spring框架.html">
            
                <a href="../整合/spring框架.html">
            
                    
                    Spring框架
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >Spring</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="spring-&#x57FA;&#x672C;&#x4F7F;&#x7528;">Spring &#x57FA;&#x672C;&#x4F7F;&#x7528;</h1>
<h1 id="spring-&#x4E2D;-bean-&#x590D;&#x6742;&#x7C7B;&#x578B;-&#x8D4B;&#x521D;&#x59CB;&#x503C;">spring &#x4E2D; Bean &#x590D;&#x6742;&#x7C7B;&#x578B; &#x8D4B;&#x521D;&#x59CB;&#x503C;</h1>
<blockquote>
<p>array, list, set, map, &#x65E5;&#x671F;</p>
</blockquote>
<h1 id="spring-&#x6846;&#x67B6;&#x4E2D;aop">Spring &#x6846;&#x67B6;&#x4E2D;AOP</h1>
<p>&#x4EE3;&#x7406;&#x6A21;&#x5F0F;&#x8BB2;&#x89E3;</p>
<p>&#x4F5C;&#x7528;: &#x5728;&#x4E0D;&#x4FEE;&#x6539;&#x539F;&#x59CB;&#x4EE3;&#x7801;&#x7684;&#x60C5;&#x51B5;&#x4E0B;,&#x901A;&#x8FC7;&#x4EE3;&#x7406;&#x7C7B;,&#x5BF9;&#x539F;&#x59CB;&#x7C7B;&#x589E;&#x52A0;&#x989D;&#x5916;&#x7684;&#x529F;&#x80FD; </p>
<h2 id="11-&#x9759;&#x6001;&#x4EE3;&#x7406;">1.1 &#x9759;&#x6001;&#x4EE3;&#x7406;</h2>
<blockquote>
<p>&#x57FA;&#x4E8E;&#x63A5;&#x53E3;&#x7684;&#x4EE3;&#x7406;</p>
</blockquote>
<p><strong>&#x5F00;&#x53D1;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x7684;&#x539F;&#x5219;:</strong></p>
<ol>
<li>&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x9700;&#x8981;&#x5B9E;&#x73B0;&#x88AB;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x4E00;&#x6837;&#x7684;&#x63A5;&#x53E3; --&gt; &#x9762;&#x5411;&#x63A5;&#x53E3;&#x5F00;&#x53D1;</li>
<li>&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x8981;&#x4F9D;&#x8D56;&#x88AB;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;                        --&gt; &#x4FDD;&#x6301;&#x539F;&#x6709;&#x529F;&#x80FD;&#x4E0D;&#x53D8;</li>
</ol>
<p>&#x4F18;&#x70B9;: &#x7B80;&#x5355;, &#x89E3;&#x51B3;&#x4E86;&#x4E0D;&#x4FEE;&#x6539;&#x6E90;&#x7801;&#x5C31;&#x80FD;&#x5B9E;&#x73B0;&#x529F;&#x80FD;&#x589E;&#x5F3A;</p>
<p>&#x7F3A;&#x70B9;: &#x4EE3;&#x7801;&#x4E0D;&#x5B9C;&#x7EF4;&#x62A4;, &#x56E0;&#x4E3A;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x9700;&#x8981;&#x5B9E;&#x73B0;&#x88AB;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x540C;&#x6837;&#x7684;&#x63A5;&#x53E3;,&#x63A5;&#x53E3;&#x589E;&#x52A0;&#x65F6;,&#x53CC;&#x65B9;&#x90FD;&#x9700;&#x8981;&#x7EF4;&#x62A4;</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UserMapperImplStaticProxy</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">UserMapper</span> </span>{

    <span class="hljs-keyword">private</span> UserMapperImpl userMapperImpl = <span class="hljs-keyword">new</span> UserMapperImpl();

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> Integer <span class="hljs-title">delete</span><span class="hljs-params">(Integer id)</span> </span>{
        System.out.println(<span class="hljs-string">&quot;-----------log&#x65E5;&#x5FD7;-------------&quot;</span>);
        Integer delete = userMapperImpl.delete(id);
        System.out.println(<span class="hljs-string">&quot;-----------log&#x65E5;&#x5FD7;-------------&quot;</span>);
        <span class="hljs-keyword">return</span> delete;
    }

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> Integer <span class="hljs-title">add</span><span class="hljs-params">()</span> </span>{
        System.out.println(<span class="hljs-string">&quot;-----------log&#x65E5;&#x5FD7;-------------&quot;</span>);
        Integer add = userMapperImpl.add();
        System.out.println(<span class="hljs-string">&quot;-----------log&#x65E5;&#x5FD7;-------------&quot;</span>);
        <span class="hljs-keyword">return</span> add;
    }

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> Integer <span class="hljs-title">update</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">null</span>;
    }
}
</code></pre>
<h2 id="12-jdk&#x7684;&#x52A8;&#x6001;&#x4EE3;&#x7406;">1.2 jdk&#x7684;&#x52A8;&#x6001;&#x4EE3;&#x7406;</h2>
<blockquote>
<p>&#x7A0B;&#x5E8F;&#x8FD0;&#x884C;&#x8FC7;&#x7A0B;&#x4E2D;, &#x901A;&#x8FC7;jdk&#x63D0;&#x4F9B;&#x7684;&#x4EE3;&#x7406;&#x6280;&#x672F;, &#x52A8;&#x6001;&#x7684;&#x4E3A;&#x67D0;&#x4E2A;&#x7C7B;&#x4EA7;&#x751F;&#x52A8;&#x6001;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x7684;&#x8FC7;&#x7A0B;</p>
</blockquote>
<p><strong>&#x5F00;&#x53D1;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x7684;&#x539F;&#x5219;:</strong></p>
<ol>
<li>&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x4E0D;&#x9700;&#x8981;&#x5B9E;&#x73B0;&#x63A5;&#x53E3;, &#x4F46;&#x662F;&#x88AB;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;( &#x76EE;&#x6807;&#x5BF9;&#x8C61; )&#x8981;&#x5B9E;&#x73B0;&#x63A5;&#x53E3;, &#x5426;&#x5219;&#x4E0D;&#x80FD;&#x4F7F;&#x7528;JDK&#x52A8;&#x6001;&#x4EE3;&#x7406;</li>
<li>&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x7684;&#x751F;&#x6210;, &#x662F;&#x4F7F;&#x7528; JDK &#x539F;&#x751F;&#x7684; API ,&#x52A8;&#x6001;&#x7684;&#x5728;&#x5185;&#x5B58;&#x6784;&#x5EFA;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;</li>
<li>&#x52A8;&#x6001;&#x4EE3;&#x7406;&#x4E5F;&#x53EB;&#x505A;: JDK &#x4EE3;&#x7406;, &#x63A5;&#x53E3;&#x4EE3;&#x7406;</li>
</ol>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">JDKDynamicProxy</span> </span>{

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{

        <span class="hljs-keyword">final</span> UserMapperImpl userMapperImpl = <span class="hljs-keyword">new</span> UserMapperImpl();

        <span class="hljs-comment">//&#x901A;&#x8FC7;JDK&#x7684;&#x52A8;&#x6001;&#x4EE3;&#x7406;&#x65B9;&#x5F0F; &#x83B7;&#x53D6; UserMapperImpl&#x7684;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;</span>
        <span class="hljs-comment">/*
        * &#x53C2;&#x6570;1&#xFF1A;  ClassLoader loader  &#x7C7B;&#x52A0;&#x8F7D;&#x5668;
        *       &#x7C7B;&#x52A0;&#x8F7D;&#x5668;&#x7684;&#x4F5C;&#x7528;&#xFF1A; &#x4EE3;&#x7406;&#x7C7B;&#x662F;&#x4E0D;&#x4F1A;&#x88AB;&#x5206;&#x914D;&#x7C7B;&#x52A0;&#x8F7D;&#x5668;
        *       &#x501F;&#x7528;&#x5176;&#x5B83;&#x7C7B;&#x7684;&#x52A0;&#x8F7D;&#x5668; &#x5B9E;&#x73B0;&#x7C7B;&#x7684;&#x52A0;&#x8F7D;&#x548C;&#x5BF9;&#x8C61;&#x7684;&#x521B;&#x5EFA;
        * &#x53C2;&#x6570;2:   Class&lt;?&gt;[] interfaces
        *         &#x88AB;&#x4EE3;&#x7406;&#x7C7B;&#x5B9E;&#x73B0;&#x7684;&#x63A5;&#x53E3;    Class
        * &#x53C2;&#x6570;3:   InvocationHandler
        *         &#x8981;&#x5B9E;&#x73B0;&#x529F;&#x80FD;&#x589E;&#x5F3A;&#x7684;&#x5BF9;&#x8C61;
        * */</span>

        Class clazz = UserMapperImpl.class;
        Class[] interfaces = clazz.getInterfaces();

        <span class="hljs-comment">// &#x901A;&#x8FC7;&#x533F;&#x540D;&#x5185;&#x90E8;&#x7C7B; &#x521B;&#x5EFA;&#x4E86;InvocationHandler&#x7C7B;&#x578B;&#x7684;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;</span>
        InvocationHandler  invocationHandler = <span class="hljs-keyword">new</span> InvocationHandler() {
            <span class="hljs-comment">//&#x7F16;&#x5199;&#x529F;&#x80FD;&#x589E;&#x5F3A;&#x65B9;&#x6CD5;</span>
            <span class="hljs-comment">/*
            *Object proxy  &#x751F;&#x6210;&#x7684;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;
            *Method method  &#x65B9;&#x6CD5;&#x5BF9;&#x8C61;    &#x901A;&#x8FC7;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x8C03;&#x7528;&#x65B9;&#x6CD5;&#x65F6;&#x90A3;&#x4E48;&#x4F1A;&#x5C06;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x8C03;&#x7528;&#x7684;&#x65B9;&#x5F0F; &#x5C01;&#x88C5;&#x6210;&#x5BF9;&#x8C61;&#x4F20;&#x5165;&#x5F53;&#x524D;&#x65B9;&#x6CD5;
            *Object[] args  &#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x8C03;&#x7528;&#x65B9;&#x6CD5;&#x7684;&#x53C2;&#x6570; &#x4E5F;&#x4F1A;&#x4EE5;&#x6570;&#x7EC4;&#x7684;&#x5F62;&#x5F0F;&#x4F20;&#x5165;&#x5F53;&#x524D;&#x65B9;&#x6CD5;
            *
            * return Object   &#x6267;&#x884C;method&#x65B9;&#x6CD5;&#x7684;&#x8FD4;&#x56DE;&#x503C;
            * */</span>
            <span class="hljs-meta">@Override</span>
            <span class="hljs-function"><span class="hljs-keyword">public</span> Object <span class="hljs-title">invoke</span><span class="hljs-params">(Object proxy, Method method, Object[] args)</span> <span class="hljs-keyword">throws</span> Throwable </span>{

                String name = method.getName();
                System.out.println(<span class="hljs-string">&quot;method name = &quot;</span>+name);

                System.out.println(<span class="hljs-string">&quot;args = &quot;</span> + args[<span class="hljs-number">0</span>]);

                System.out.println(<span class="hljs-string">&quot;----------log&#x65E5;&#x5FD7;-----------&quot;</span>);
                Object invoke = method.invoke(userMapperImpl, args);

                <span class="hljs-keyword">return</span> invoke;
            }
        };
        <span class="hljs-comment">// o &#x901A;&#x8FC7;&#x52A8;&#x6001;&#x4EE3;&#x7406;&#x65B9;&#x5F0F;&#x83B7;&#x53D6;&#x7684;&#x52A8;&#x6001;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;</span>
        <span class="hljs-comment">/**
         *&#x53C2;&#x6570;1&#xFF1A;&#x7C7B;&#x52A0;&#x8F7D;&#x5668;&#xFF0C;&#x52A8;&#x6001;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x6CA1;&#x6709;&#x7C7B;&#x52A0;&#x8F7D;&#x5668; &#x9700;&#x8981;&#x501F;&#x52A9;&#x522B;&#x7684;&#x7C7B;&#x7684;&#x52A0;&#x8F7D;&#x5668;&#x5B9E;&#x73B0;&#x7C7B;&#x7684;&#x52A0;&#x8F7D;
         * &#x7C7B;&#x52A0;&#x8F7D;&#x5668;&#x7684;&#x4F5C;&#x7528;&#xFF1A;
         *  1.&#x52A0;&#x8F7D;class&#x6587;&#x4EF6;&#x5230;JVM&#x865A;&#x62DF;&#x673A;
         *  2.&#x521B;&#x5EFA;&#x7C7B;&#x7684;class&#x5BF9;&#x8C61;&#xFF0C;&#x8FDB;&#x800C;&#x521B;&#x5EFA;&#x7C7B;&#x7684;&#x5B9E;&#x4F8B;&#x5316;&#x5BF9;&#x8C61;
         *
         * &#x53C2;&#x6570;2:&#x539F;&#x59CB;&#x7C7B;&#x5B9E;&#x73B0;&#x7684;&#x6240;&#x6709;&#x63A5;&#x53E3;  &#x57FA;&#x4E8E;jdk&#x7684;&#x52A8;&#x6001;&#x4EE3;&#x7406;&#x8981;&#x6C42;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x548C;&#x539F;&#x59CB;&#x5BF9;&#x8C61;&#x8981;&#x5B9E;&#x73B0;&#x76F8;&#x540C;&#x7684;&#x63A5;&#x53E3;
         *
         * &#x53C2;&#x6570;3&#xFF1A;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x989D;&#x5916;&#x589E;&#x52A0;&#x7684;&#x529F;&#x80FD;  InvocationHandler
         *
         */</span>
        UserMapper  o = (UserMapper) Proxy.newProxyInstance(JDKDynamicProxy.class.getClassLoader(), interfaces, invocationHandler);
        Integer delete = o.delete(<span class="hljs-number">1</span>);
        System.out.println(<span class="hljs-string">&quot;delete = &quot;</span> + delete);

    }
}
</code></pre>
<h2 id="13-cglib&#x4EE3;&#x7406;">1.3 cglib&#x4EE3;&#x7406;</h2>
<p><strong>&#x5F00;&#x53D1;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x7684;&#x539F;&#x5219;&#xFF1A;</strong></p>
<ol>
<li>&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x65E0;&#x9700;&#x548C;&#x76EE;&#x6807;&#x5BF9;&#x8C61;&#x5B9E;&#x73B0;&#x540C;&#x6837;&#x7684;&#x63A5;&#x53E3;</li>
<li>&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x9700;&#x8981;&#x548C;&#x76EE;&#x6807;&#x5BF9;&#x8C61;&#x5B58;&#x5728;&#x7236;&#x5B50;&#x7C7B;&#x5173;&#x7CFB;</li>
</ol>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CglibProxy</span> </span>{

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{

        UserMapperImpl userMapper = <span class="hljs-keyword">new</span> UserMapperImpl();

        Enhancer enhancer = <span class="hljs-keyword">new</span> Enhancer();

        <span class="hljs-comment">//&#x8BBE;&#x7F6E;&#x751F;&#x6210;&#x7684;&#x4EE3;&#x7406;&#x7C7B;&#x7684;&#x7236;&#x7C7B;</span>
        enhancer.setSuperclass(UserMapperImpl.class);
        <span class="hljs-comment">//&#x8BBE;&#x7F6E;&#x4EE3;&#x7406;&#x7C7B;&#x7684;&#x589E;&#x5F3A;&#x7684;&#x529F;&#x80FD;</span>
        MethodInterceptor methodInterceptor = <span class="hljs-keyword">new</span> MethodInterceptor() {

            <span class="hljs-comment">// Method method      Object[] objects</span>
            <span class="hljs-meta">@Override</span>
            <span class="hljs-function"><span class="hljs-keyword">public</span> Object <span class="hljs-title">intercept</span><span class="hljs-params">(Object o, Method method, Object[] objects, MethodProxy methodProxy)</span> <span class="hljs-keyword">throws</span> Throwable </span>{

                System.out.println(<span class="hljs-string">&quot;---------log&#x65E5;&#x5FD7;------------&quot;</span>);

                Object invoke = method.invoke(userMapper, objects);

                System.out.println(<span class="hljs-string">&quot;---------log&#x65E5;&#x5FD7;------------&quot;</span>);
                <span class="hljs-keyword">return</span> invoke;
            }
        };
        enhancer.setCallback(methodInterceptor);
        <span class="hljs-comment">// &#x521B;&#x5EFA;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;   &#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x662F; UserMapperImpl&#x7684;&#x5B50;&#x7C7B;</span>
        UserMapperImpl o = (UserMapperImpl) enhancer.create();
        Integer delete = o.delete(<span class="hljs-number">1</span>);
        System.out.println(<span class="hljs-string">&quot;delete = &quot;</span> + delete);


    }
}
</code></pre>
<h1 id="aop-&#x672F;&#x8BED;">AOP &#x672F;&#x8BED;</h1>
<ul>
<li><p>&#x6A2A;&#x5207;&#x5173;&#x6CE8;&#x70B9;:&#x8DE8;&#x8D8A;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x591A;&#x4E2A;&#x6A21;&#x5757;&#x7684;&#x65B9;&#x6CD5;&#x6216;&#x529F;&#x80FD;&#x3002;&#x5373;&#x662F;&#xFF0C;&#x4E0E;&#x6211;&#x4EEC;&#x4E1A;&#x52A1;&#x903B;&#x8F91;&#x65E0;&#x5173;&#x7684;&#xFF0C;&#x4F46;&#x662F;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x5173;&#x6CE8;&#x7684;&#x90E8;&#x5206;&#xFF0C;&#x5C31;&#x662F;&#x6A2A;&#x5207;&#x5173;&#x6CE8;&#x70B9;&#x3002;&#x5982;&#x65E5;&#x5FD7;,&#x5B89;&#x5168;,&#x7F13;&#x5B58;,&#x4E8B;&#x52A1;&#x7B49;&#x7B49;....</p>
</li>
<li><p>&#x5207;&#x9762;( ASPECT ): &#x6A2A;&#x5207;&#x5173;&#x6CE8;&#x70B9;&#x6A21;&#x5757;&#x5316;&#x7684;&#x7279;&#x6B8A;&#x5BF9;&#x8C61;, &#x5373;,&#x662F;&#x4E00;&#x4E2A;&#x7C7B;</p>
</li>
<li><p>&#x901A;&#x77E5;( Advice ): &#x5207;&#x9762;&#x9700;&#x8981;&#x5B8C;&#x6210;&#x7684;&#x4EFB;&#x52A1;, &#x5373;,&#x7C7B;&#x4E2D;&#x7684;&#x65B9;&#x6CD5;</p>
<p>&#x524D;&#x7F6E;&#x901A;&#x77E5;, &#x540E;&#x7F6E;&#x901A;&#x77E5;, &#x73AF;&#x7ED5;&#x901A;&#x77E5;, &#x5F02;&#x5E38;&#x901A;&#x77E5;, &#x6700;&#x7EC8;&#x901A;&#x77E5;</p>
</li>
<li><p>&#x76EE;&#x6807;( Target ): &#x88AB;&#x901A;&#x77E5;&#x5BF9;&#x8C61;</p>
</li>
<li><p>&#x4EE3;&#x7406;( Proxy ): &#x5411;&#x76EE;&#x6807;&#x5BF9;&#x8C61;&#x901A;&#x77E5;&#x540E;&#x521B;&#x5EFA;&#x7684;&#x5BF9;&#x8C61;</p>
</li>
<li><p>&#x5207;&#x5165;&#x70B9;( PointCut ): &#x5207;&#x9762;&#x901A;&#x77E5;&#x6267;&#x884C;&#x7684;&quot;&#x5730;&#x70B9;&quot;&#x7684;&#x5B9A;&#x4E49;</p>
</li>
<li><p>&#x8FDE;&#x63A5;&#x70B9;( JoinCut ):  &#x4E0E;&#x5207;&#x5165;&#x70B9;&#x5339;&#x914D;&#x6267;&#x884C;&#x70B9;</p>
</li>
</ul>
<h2 id="1-&#x57FA;&#x4E8E;&#x63A5;&#x53E3;&#x5F62;&#x5F0F;&#x5B9E;&#x73B0;">1. &#x57FA;&#x4E8E;&#x63A5;&#x53E3;&#x5F62;&#x5F0F;&#x5B9E;&#x73B0;</h2>
<blockquote>
<p>&#x4F7F;&#x7528; Spring-aop &#x63A5;&#x53E3;&#x65B9;&#x5F0F;&#x5B9E;&#x73B0; aop , &#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x81EA;&#x5B9A;&#x4E49;&#x901A;&#x77E5;&#x6765;&#x4F9B;Spring-aop&#x8BC6;&#x522B;</p>
</blockquote>
<p><strong>&#x5207;&#x5165;&#x70B9;&#x8868;&#x8FBE;&#x5F0F;</strong></p>
<p>&#x4F5C;&#x7528;: &#x58F0;&#x660E;&#x5BF9;&#x54EA;&#x4E2A;&#x7C7B;&#x4E2D;&#x7684;&#x54EA;&#x4E2A;&#x65B9;&#x6CD5;&#x8FDB;&#x884C;&#x589E;&#x5F3A;</p>
<p>&#x8BED;&#x6CD5;:</p>
<p>execution([ &#x8BBF;&#x95EE;&#x5168;&#x9650;&#x4FEE;&#x9970;&#x7B26; ] &#x8FD4;&#x56DE;&#x503C;&#x7C7B;&#x578B; [ &#x5168;&#x9650;&#x5B9A;&#x7C7B;&#x540D; ] &#x65B9;&#x6CD5;&#x540D;( &#x53C2;&#x6570;&#x5217;&#x8868; ) [ &#x5F02;&#x5E38; ])</p>
<ul>
<li>&#x8BBF;&#x95EE;&#x5168;&#x9650;&#x4FEE;&#x9970;&#x7B26;:<ul>
<li>&#x53EF;&#x9009;&#x9879;, &#x4E0D;&#x5199;&#x5C31;&#x662F;&#x5305;&#x542B;&#x6240;&#x6709;&#x4FEE;&#x9970;&#x7B26;</li>
<li>&#x5199;public &#x5C31;&#x8868;&#x793A;&#x53EA;&#x5305;&#x62EC; &#x516C;&#x5F00;&#x7684;&#x65B9;&#x6CD5;</li>
</ul>
</li>
<li>&#x8FD4;&#x56DE;&#x503C;&#x7C7B;&#x578B;<ul>
<li>&#x5FC5;&#x586B;&#x9879;, * &#x8868;&#x793A;&#x4EFB;&#x610F;&#x7C7B;&#x578B;&#x7684;&#x8FD4;&#x56DE;&#x503C;</li>
</ul>
</li>
<li>&#x5168;&#x9650;&#x5B9A;&#x7C7B;&#x540D;<ul>
<li>&#x53EF;&#x9009;&#x9879;,  &#x4E24;&#x4E2A;&#x70B9; .. &#x8868;&#x793A;&#x53CD;&#x5168;&#x5305;&#x4EE5;&#x53CA;&#x5B50;&#x5305;&#x4E0B;&#x7684;&#x6240;&#x6709;&#x7C7B;, &#x7701;&#x7565;&#x8868;&#x793A;&#x6240;&#x6709;&#x7C7B;</li>
</ul>
</li>
<li>&#x65B9;&#x6CD5;&#x540D;<ul>
<li>&#x5FC5;&#x586B;&#x9879;, <em> &#x8868;&#x793A;&#x6240;&#x6709;&#x65B9;&#x6CD5;, set</em> &#x8868;&#x793A;&#x6240;&#x6709;set&#x65B9;&#x6CD5;</li>
</ul>
</li>
<li>&#x53C2;&#x6570;&#x5217;&#x8868;<ul>
<li>&#x5FC5;&#x586B;&#x9879;</li>
<li>() &#x8868;&#x793A;&#x6CA1;&#x6709;&#x53C2;&#x6570;&#x7684;&#x65B9;&#x6CD5;</li>
<li>(..)  &#x8868;&#x793A;&#x4EFB;&#x610F;&#x53C2;&#x6570;&#x7C7B;&#x578B;&#x6570;&#x91CF;&#x7684;&#x65B9;&#x6CD5;</li>
<li>(*) &#x8868;&#x793A;&#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x7684;&#x65B9;&#x6CD5;</li>
<li>(*, String) &#x8868;&#x793A;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x7C7B;&#x578B;&#x4EFB;&#x610F;, &#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x7C7B;&#x578B;&#x4E3A; String</li>
</ul>
</li>
<li>&#x5F02;&#x5E38;&#x4FE1;&#x606F;<ul>
<li>&#x53EF;&#x9009;&#x9879;, &#x7701;&#x7565;&#x662F;&#x8868;&#x793A;&#x4EFB;&#x4F55;&#x5F02;&#x5E38;&#x4FE1;&#x606F;</li>
</ul>
</li>
</ul>
<p><strong>&#x5BF9;&#x5E94;&#x7684;&#x63A5;&#x53E3;&#x662F;:</strong></p>
<ol>
<li><p>&#x524D;&#x7F6E;&#x901A;&#x77E5;: MethodBeforeAdvice</p>
</li>
<li><p>&#x8FD4;&#x56DE;&#x901A;&#x77E5;: AfterReturningAdvice</p>
</li>
<li><p>&#x5F02;&#x5E38;&#x901A;&#x77E5;: ThrowsAdvice</p>
</li>
<li><p>&#x73AF;&#x7ED5;&#x901A;&#x77E5;: MethodIntercepter</p>
</li>
</ol>
<pre><code class="lang-java">   public class MyBeforeAdvice implements MethodBeforeAdvice {
       @Override
       public void before(Method method, Object[] args, Object target) throws Throwable {
           System.out.println(&quot;========log=======&quot;);
           String name = method.getName();
           System.out.println(&quot;name = &quot; + name);
           System.out.println(&quot;method.args = &quot; + Arrays.toString(args));
       }
   }



   &lt;!--1.&#x6258;&#x7BA1;&#x901A;&#x77E5;&#x548C;&#x88AB;&#x4EE3;&#x7406;&#x7684;&#x7C7B;--&gt;
       &lt;bean id=&quot;myBeforeAdvice&quot; class=&quot;cn.kgc.spring08.advice.MyBeforeAdvice&quot;&gt;&lt;/bean&gt;
       &lt;bean id=&quot;calculator&quot; class=&quot;cn.kgc.spring08.entity.Calculator&quot;&gt;&lt;/bean&gt;

       &lt;!--&#x914D;&#x7F6E;aop&#x76F8;&#x5173;&#x53C2;&#x6570;--&gt;
       &lt;aop:config&gt;
           &lt;!--&#x5B9A;&#x4E49;&#x5207;&#x70B9;
               &#x5207;&#x70B9;&#x8868;&#x8FBE;&#x5F0F;&#xFF1A;  &#x4F7F;&#x7528;&#x4E00;&#x4E2A;&#x8868;&#x8FBE;&#x5F0F;&#x9009;&#x62E9;&#x90A3;&#x4E9B;&#x65B9;&#x6CD5;&#x9700;&#x8981;&#x88AB;&#x589E;&#x5F3A;
               execution([&#x8BBF;&#x95EE;&#x6743;&#x9650;&#x4FEE;&#x9970;&#x7B26;] &#x8FD4;&#x56DE;&#x503C; [&#x5168;&#x9650;&#x5B9A;&#x540D;]&#x65B9;&#x6CD5;&#x540D;(&#x53C2;&#x6570;&#x5217;&#x8868;)[&#x5F02;&#x5E38;])
           --&gt;
           &lt;aop:pointcut id=&quot;p1&quot; expression=&quot;execution(public * *(..))&quot;/&gt;
           &lt;!--&#x914D;&#x7F6E;&#x901A;&#x77E5;
           advice-ref :&#x5173;&#x8054;&#x901A;&#x77E5;&#x5BF9;&#x8C61;
           pointcut-ref&#xFF1A; &#x5173;&#x8054;&#x5207;&#x70B9;&#x5BF9;&#x8C61;
           --&gt;
           &lt;aop:advisor advice-ref=&quot;myBeforeAdvice&quot; pointcut-ref=&quot;p1&quot;&gt;&lt;/aop:advisor&gt;
       &lt;/aop:config&gt;



   @Test
   public void shouldAnswerWithTrue() {
       ApplicationContext applicationContext = new ClassPathXmlApplicationContext(&quot;spring-config.xml&quot;);
       Calculator cal = applicationContext.getBean(&quot;cal&quot;, Calculator.class);
       Integer add = cal.add(4, 6);
       System.out.println(&quot;add = &quot; + add);

   }
</code></pre>
<p><strong>&#x901A;&#x77E5;&#x7684;&#x7C7B;&#x578B;</strong></p>
<table>
<thead>
<tr>
<th>&#x901A;&#x77E5;</th>
<th>&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td>&#x524D;&#x7F6E;&#x901A;&#x77E5;</td>
<td>&#x5728;&#x4E00;&#x4E2A;&#x65B9;&#x6CD5;&#x6267;&#x884C;&#x524D;,&#x6267;&#x884C;&#x901A;&#x77E5;</td>
</tr>
<tr>
<td>&#x540E;&#x7F6E;&#x901A;&#x77E5;</td>
<td>&#x5728;&#x4E00;&#x4E2A;&#x65B9;&#x6CD5;&#x6267;&#x884C;&#x540E;,&#x6267;&#x884C;&#x901A;&#x77E5;</td>
</tr>
<tr>
<td>&#x8FD4;&#x56DE;&#x540E;&#x901A;&#x77E5;(&#x6700;&#x7EC8;&#x901A;&#x77E5;)</td>
<td>&#x5728;&#x4E00;&#x4E2A;&#x65B9;&#x6CD5;&#x6267;&#x884C;&#x4E4B;&#x540E;,&#x53EA;&#x6709;&#x5728;&#x65B9;&#x6CD5;&#x5B8C;&#x6210;&#x65F6;,&#x624D;&#x80FD;&#x6267;&#x884C;&#x901A;&#x77E5;</td>
</tr>
<tr>
<td>&#x73AF;&#x7ED5;&#x901A;&#x77E5;</td>
<td>&#x5728;&#x4E00;&#x4E2A;&#x65B9;&#x6CD5;&#x8C03;&#x7528; &#x524D;&#x540E;, &#x6267;&#x884C;&#x901A;&#x77E5;</td>
</tr>
<tr>
<td>&#x5F02;&#x5E38;&#x901A;&#x77E5;</td>
<td>&#x5728;&#x4E00;&#x4E2A;&#x65B9;&#x6CD5;&#x6267;&#x884C;&#x4E4B;&#x540E;, &#x53EA;&#x6709;&#x65B9;&#x6CD5;&#x9000;&#x51FA;&#x629B;&#x51FA;&#x5F02;&#x5E38;, &#x624D;&#x80FD;&#x6267;&#x884C;&#x901A;&#x77E5;</td>
</tr>
</tbody>
</table>
<h2 id="2-&#x57FA;&#x4E8E;aspectj-&#x5B9E;&#x73B0;-aop-&#x64CD;&#x4F5C;">2 &#x57FA;&#x4E8E;Aspectj &#x5B9E;&#x73B0; AOP &#x64CD;&#x4F5C;</h2>
<ol>
<li>&#x57FA;&#x4E8E; xml &#x914D;&#x7F6E;&#x6587;&#x4EF6;</li>
<li>&#x57FA;&#x4E8E;&#x6CE8;&#x89E3;&#x7684;&#x5F62;&#x5F0F;&#x5B9E;&#x73B0;</li>
</ol>
<pre><code class="lang-java">xml &#x914D;&#x7F6E;
&lt;!--  &#x6CE8;&#x89E3;&#x5F00;&#x53D1;:&#x5F00;&#x542F;&#x5305;&#x626B;&#x63CF;   --&gt;
&lt;context:component-scan base-package=&quot;org.example&quot;&gt;&lt;/context:component-scan&gt;
&lt;!--  &#x5F00;&#x542F; Aspectj &#x81EA;&#x52A8;&#x4EE3;&#x7406;  &#x9ED8;&#x8BA4;&#x4F7F;&#x7528; jdk&#x7684;&#x65B9;&#x5F0F;,proxy-target-class=&quot;true&quot; &#x4F7F;&#x7528; Cglib   --&gt;
&lt;aop:aspectj-autoproxy&gt;&lt;/aop:aspectj-autoproxy&gt;


&#x901A;&#x77E5;&#x7C7B;
@Component
@Aspect
public class LogAdvice {
    @Before(&quot;execution(* *(..))&quot;)
    public void beforeAdvice(){
        System.out.println(&quot;========&#x524D;&#x7F6E;&#x901A;&#x77E5;=======&quot;);
    }

    @AfterReturning(&quot;execution(* *(..))&quot;)
    public void afterReturning(){
        System.out.println(&quot;========&#x540E;&#x7F6E;&#x901A;&#x77E5;=======&quot;);
    }

    @After(&quot;execution(* *(..))&quot;)
    public void after(){
        System.out.println(&quot;========&#x6700;&#x7EC8;&#x901A;&#x77E5;=======&quot;); // &#x65E0;&#x8BBA;&#x7A0B;&#x5E8F;&#x65F6;&#x5019;&#x5F02;&#x5E38;&#x90FD;&#x4F1A;&#x6267;&#x884C;
    }


    @AfterThrowing(&quot;execution(* *(..))&quot;)
    public void afterThrowing(){
        System.out.println(&quot;========&#x5F02;&#x5E38;&#x901A;&#x77E5;=======&quot;); // &#x4E0E;&#x540E;&#x7F6E;&#x901A;&#x77E5; &#x53EA;&#x4F1A;&#x6267;&#x884C;&#x5176;&#x4E2D;&#x4E00;&#x4E2A;
    }


    @Around(&quot;execution(* *(..))&quot;)
    public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println(&quot;========&#x73AF;&#x7ED5;&#x524D;&#x901A;&#x77E5;=======&quot;);
        Object proceed = proceedingJoinPoint.proceed(); // &#x9700;&#x8981;&#x8FD4;&#x56DE;&#x6539;&#x65B9;&#x6CD5;&#x7684;&#x7ED3;&#x679C;&#x5426;&#x5219;, &#x76EE;&#x6807;&#x5BF9;&#x8C61;&#x6267;&#x884C;&#x7684;&#x65B9;&#x6CD5;&#x65E0;&#x8FD4;&#x56DE;&#x503C;
        System.out.println(&quot;========&#x73AF;&#x7ED5;&#x540E;&#x901A;&#x77E5;=======&quot;);
        return proceed;
    }
}


@Test
public void shouldAnswerWithTrue() {
    ApplicationContext applicationContext = new ClassPathXmlApplicationContext(&quot;spring-config.xml&quot;);
    Calculator cal = applicationContext.getBean(&quot;cal&quot;, Calculator.class);
    System.out.println(&quot;cal = &quot; + cal.getClass());
    Integer add = cal.add(4, 6);
//        System.out.println(&quot;add = &quot; + add);
    System.out.println();
    System.out.println();
    Integer div = cal.div(2, 0);
}


&#x6267;&#x884C;&#x7ED3;&#x679C;
cal = class org.example.entity.Calculator$$EnhancerBySpringCGLIB$$dc9faed8
========&#x73AF;&#x7ED5;&#x524D;&#x901A;&#x77E5;=======
========&#x524D;&#x7F6E;&#x901A;&#x77E5;=======
Calculator &#x6267;&#x884C; add()
========&#x540E;&#x7F6E;&#x901A;&#x77E5;=======
========&#x6700;&#x7EC8;&#x901A;&#x77E5;=======
========&#x73AF;&#x7ED5;&#x540E;&#x901A;&#x77E5;=======


add = 10
========&#x73AF;&#x7ED5;&#x524D;&#x901A;&#x77E5;=======
========&#x524D;&#x7F6E;&#x901A;&#x77E5;=======
Calculator &#x6267;&#x884C; div()
========&#x5F02;&#x5E38;&#x901A;&#x77E5;=======
========&#x6700;&#x7EC8;&#x901A;&#x77E5;=======

java.lang.ArithmeticException: / by zero
</code></pre>
<h1 id="sm-&#x6846;&#x67B6;&#x6574;&#x5408;">SM &#x6846;&#x67B6;&#x6574;&#x5408;</h1>
<p><strong>&#x4F9D;&#x8D56;</strong></p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">dependencies</span>&gt;</span>
<span class="hljs-comment">&lt;!--    mysql&#x9A71;&#x52A8;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>mysql<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>mysql-connector-java<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>5.1.44<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
    <span class="hljs-comment">&lt;!--druid--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.alibaba<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>druid<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.1.10<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
<span class="hljs-comment">&lt;!--mybatis--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.mybatis<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>mybatis<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>3.5.7<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

    <span class="hljs-comment">&lt;!--IOC &#x4F9D;&#x8D56;&#x6CE8;&#x5165;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-context<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>5.3.9<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

    <span class="hljs-comment">&lt;!--mybatis&amp;spring &#x6574;&#x5408;&#x5305;--&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.mybatis<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>mybatis-spring<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>2.0.5<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

    <span class="hljs-comment">&lt;!--aspects &#x5207;&#x9762;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-aspects<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>5.3.9<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

    <span class="hljs-comment">&lt;!--jdbc--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-jdbc<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>5.3.9<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

    <span class="hljs-comment">&lt;!--lombok--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.projectlombok<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>lombok<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.18.16<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

    <span class="hljs-comment">&lt;!-- &#x65E5;&#x5FD7;&#x5DE5;&#x5177;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>log4j<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>log4j<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.2.17<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
    <span class="hljs-comment">&lt;!--mybatis&#x5206;&#x9875;&#x63D2;&#x4EF6;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.github.pagehelper<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>pagehelper<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>5.2.1<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
<span class="hljs-comment">&lt;!--&#x6D4B;&#x8BD5;&#x5DE5;&#x5177;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>junit<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>junit<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>4.11<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">scope</span>&gt;</span>test<span class="hljs-tag">&lt;/<span class="hljs-name">scope</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

  <span class="hljs-tag">&lt;/<span class="hljs-name">dependencies</span>&gt;</span>
</code></pre>
<p>&#x5C06; mybatis &#x548C; spring &#x6574;&#x5408;&#x5C31;&#x662F;&#x5C06; mybatis-config.xml &#x4E2D;&#x7684;&#x914D;&#x7F6E;&#x90FD; &#x5F15;&#x5165;&#x5230; spring-config.xml &#x4E2D;</p>
<p>&#x5305;&#x62EC;: &#x5916;&#x90E8;&#x914D;&#x7F6E;properties&#x6587;&#x4EF6;,&#x522B;&#x540D;, &#x6570;&#x636E;&#x6E90;, &#x4E8B;&#x52A1;, mapper &#x6620;&#x5C04;, &#x548C;&#x5269;&#x4F59;&#x914D;&#x7F6E;</p>
<p><strong>&#x6574;&#x5408;&#x540E;&#x7684; mybatis.xml</strong></p>
<pre><code class="lang-xml"><span class="php"><span class="hljs-meta">&lt;?</span>xml version=<span class="hljs-string">&quot;1.0&quot;</span> encoding=<span class="hljs-string">&quot;UTF-8&quot;</span> <span class="hljs-meta">?&gt;</span></span>
<span class="hljs-meta">&lt;!DOCTYPE configuration
        PUBLIC &quot;-//mybatis.org//DTD Config 3.0//EN&quot;
        &quot;http://mybatis.org/dtd/mybatis-3-config.dtd&quot;&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
<span class="hljs-comment">&lt;!--    &lt;properties resource=&quot;config/jdbc.properties&quot;&gt;&lt;/properties&gt;--&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">settings</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">setting</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;logImpl&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;STDOUT_LOGGING&quot;</span>/&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">setting</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;mapUnderscoreToCamelCase&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;true&quot;</span>/&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">setting</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;lazyLoadingEnabled&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;false&quot;</span>/&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">settings</span>&gt;</span>

<span class="hljs-comment">&lt;!--    &lt;typeAliases&gt;--&gt;</span>
<span class="hljs-comment">&lt;!--        &lt;package name=&quot;org.example.spring09.entity&quot;/&gt;--&gt;</span>
<span class="hljs-comment">&lt;!--    &lt;/typeAliases&gt;--&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">plugins</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">plugin</span> <span class="hljs-attr">interceptor</span>=<span class="hljs-string">&quot;com.github.pagehelper.PageInterceptor&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">plugin</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">plugins</span>&gt;</span>

<span class="hljs-comment">&lt;!--    &lt;environments default=&quot;development&quot;&gt;--&gt;</span>
<span class="hljs-comment">&lt;!--        &lt;environment id=&quot;development&quot;&gt;--&gt;</span>
<span class="hljs-comment">&lt;!--            &lt;transactionManager type=&quot;JDBC&quot;/&gt;--&gt;</span>
<span class="hljs-comment">&lt;!--            &lt;dataSource type=&quot;POOLED&quot;&gt;--&gt;</span>
<span class="hljs-comment">&lt;!--                &lt;property name=&quot;driver&quot; value=&quot;${jdbc.driver}&quot;/&gt;--&gt;</span>
<span class="hljs-comment">&lt;!--                &lt;property name=&quot;url&quot; value=&quot;${jdbc.url}&quot;/&gt;--&gt;</span>
<span class="hljs-comment">&lt;!--                &lt;property name=&quot;username&quot; value=&quot;${jdbc.username}&quot;/&gt;--&gt;</span>
<span class="hljs-comment">&lt;!--                &lt;property name=&quot;password&quot; value=&quot;${jdbc.password}&quot;/&gt;--&gt;</span>
<span class="hljs-comment">&lt;!--            &lt;/dataSource&gt;--&gt;</span>
<span class="hljs-comment">&lt;!--        &lt;/environment&gt;--&gt;</span>
<span class="hljs-comment">&lt;!--    &lt;/environments&gt;--&gt;</span>

<span class="hljs-comment">&lt;!--    &lt;mappers&gt;--&gt;</span>
<span class="hljs-comment">&lt;!--        &lt;package name=&quot;org.example.spring09.mapper&quot;/&gt;--&gt;</span>
<span class="hljs-comment">&lt;!--    &lt;/mappers&gt;--&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<p><strong>&#x6574;&#x5408;&#x540E;&#x7684; spring-config.xml</strong></p>
<pre><code class="lang-xml"><span class="php"><span class="hljs-meta">&lt;?</span>xml version=<span class="hljs-string">&quot;1.0&quot;</span> encoding=<span class="hljs-string">&quot;UTF-8&quot;</span><span class="hljs-meta">?&gt;</span></span>
<span class="hljs-tag">&lt;<span class="hljs-name">beans</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/beans&quot;</span>
       <span class="hljs-attr">xmlns:xsi</span>=<span class="hljs-string">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>
       <span class="hljs-attr">xmlns:context</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/context&quot;</span>
       <span class="hljs-attr">xmlns:aop</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/aop&quot;</span> <span class="hljs-attr">xmlns:tx</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/tx&quot;</span>
       <span class="hljs-attr">xsi:schemaLocation</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd&quot;</span>&gt;</span>

    <span class="hljs-comment">&lt;!--&#x5F15;&#x5165;&#x6570;&#x636E;&#x6E90;&#x53C2;&#x6570;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">context:property-placeholder</span> <span class="hljs-attr">location</span>=<span class="hljs-string">&quot;classpath:config/jdbc.properties&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">context:property-placeholder</span>&gt;</span>

    <span class="hljs-comment">&lt;!--&#x5F00;&#x542F;&#x5305;&#x626B;&#x63CF;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">context:component-scan</span> <span class="hljs-attr">base-package</span>=<span class="hljs-string">&quot;org.example.spring09&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">context:component-scan</span>&gt;</span>
    <span class="hljs-comment">&lt;!--&#x5F00;&#x542F; aspectj &#x81EA;&#x52A8;&#x6620;&#x5C04;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">aop:aspectj-autoproxy</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">aop:aspectj-autoproxy</span>&gt;</span>

    <span class="hljs-comment">&lt;!--&#x914D;&#x7F6E;&#x6570;&#x636E;&#x6E90;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;druidDataSource&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;com.alibaba.druid.pool.DruidDataSource&quot;</span> &gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;driverClassName&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;${jdbc.driver}&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;url&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;${jdbc.url}&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;username&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;${jdbc.username}&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;password&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;${jdbc.password}&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>

    <span class="hljs-comment">&lt;!-- &#x914D;&#x7F6E;sqlSessionFactoryBean --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;sqlSessionFactoryBean&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;org.mybatis.spring.SqlSessionFactoryBean&quot;</span>&gt;</span>
        <span class="hljs-comment">&lt;!--&#x914D;&#x7F6E;&#x6570;&#x636E;&#x6E90;--&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;dataSource&quot;</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;druidDataSource&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span>
        <span class="hljs-comment">&lt;!--&#x914D;&#x7F6E;&#x522B;&#x540D;--&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;typeAliasesPackage&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;org.example.spring09.entity&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span>
        <span class="hljs-comment">&lt;!--&#x914D;&#x7F6E; mapper &#x6620;&#x5C04;&#x6587;&#x4EF6;&#x4F4D;&#x7F6E;--&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;mapperLocations&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;org/example/spring09/mapper/*.xml&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span>
        <span class="hljs-comment">&lt;!--&#x914D;&#x7F6E;&#x5269;&#x4F59; mybatis-config.xml &#x8BBE;&#x7F6E;--&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;configLocation&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;config/mybatis-config.xml&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>

    <span class="hljs-comment">&lt;!--&#x914D;&#x7F6E;&#x4E8B;&#x52A1;&#x7BA1;&#x7406;&#x5668;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;dataSourceTransactionManager&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;org.springframework.jdbc.datasource.DataSourceTransactionManager&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;dataSource&quot;</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;druidDataSource&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>
    <span class="hljs-comment">&lt;!--&#x5F00;&#x542F;&#x4E8B;&#x52A1;&#x6CE8;&#x89E3;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">tx:annotation-driven</span> <span class="hljs-attr">transaction-manager</span>=<span class="hljs-string">&quot;dataSourceTransactionManager&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">tx:annotation-driven</span>&gt;</span>

    <span class="hljs-comment">&lt;!--&#x626B;&#x63CF;mapper&#x63A5;&#x53E3;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;org.mybatis.spring.mapper.MapperScannerConfigurer&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;basePackage&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;org.example.spring09.mapper&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">beans</span>&gt;</span>
</code></pre>
<blockquote>
<p>&#x914D;&#x7F6E;&#x4E8B;&#x52A1;&#x7BA1;&#x7406;&#x5668;&#x4E4B;&#x540E;&#x8FD8;&#x9700;&#x8981;&#x5F00;&#x542F;&#x4E8B;&#x52A1;&#x6CE8;&#x89E3;&#x626B;&#x63CF;</p>
<p>&#x4F7F;&#x7528;&#x6CE8;&#x89E3;&#x8C03;&#x7528; &#x4E8B;&#x52A1;</p>
</blockquote>
<pre><code class="lang-java"><span class="hljs-keyword">package</span> org.example.spring09.service.impl;

<span class="hljs-keyword">import</span> org.example.spring09.entity.User;
<span class="hljs-keyword">import</span> org.example.spring09.mapper.UserMapper;
<span class="hljs-keyword">import</span> org.example.spring09.service.UserService;
<span class="hljs-keyword">import</span> org.springframework.beans.factory.annotation.Autowired;
<span class="hljs-keyword">import</span> org.springframework.stereotype.Service;
<span class="hljs-keyword">import</span> org.springframework.transaction.annotation.Transactional;

<span class="hljs-keyword">import</span> java.util.List;

<span class="hljs-comment">/**
 * <span class="hljs-doctag">@Author</span> Hanmo
 * <span class="hljs-doctag">@Time</span> 2022/12/7
 * <span class="hljs-doctag">@Describe</span>
 */</span>
<span class="hljs-meta">@Service</span>(<span class="hljs-string">&quot;userService&quot;</span>)
<span class="hljs-comment">//@Transactional</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UserServiceImpl</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">UserService</span> </span>{

    <span class="hljs-meta">@Autowired</span>
    <span class="hljs-keyword">private</span> UserMapper userMapper;

    <span class="hljs-comment">/**
     Transactional&#x6CE8;&#x89E3;&#x4E2D;&#x7684;&#x5C5E;&#x6027;
       isolation&#xFF1A;&#x4E8B;&#x52A1;&#x7684;&#x9694;&#x79BB;&#x7EA7;&#x522B;   READ_UNCOMMITTED READ_COMMITTED  REPEATABLE_READ  SERIALIZABLE
       propagation: &#x4E8B;&#x52A1;&#x7684;&#x4F20;&#x64AD;&#x673A;&#x5236;
         Propagation.REQUIRED  &#x9ED8;&#x8BA4;
       rollbackFor&#xFF1A; &#x6307;&#x5B9A;&#x56DE;&#x6EDA;&#x7684;&#x5F02;&#x5E38;
       noRollbackFor: &#x6307;&#x5B9A;&#x4E0D;&#x56DE;&#x6EDA;&#x7684;&#x5F02;&#x5E38;
     */</span>
    <span class="hljs-meta">@Transactional</span>
    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> List&lt;User&gt; <span class="hljs-title">selectUser</span><span class="hljs-params">()</span> </span>{
        List&lt;User&gt; users = userMapper.selectAll();
        <span class="hljs-keyword">return</span> users;
    }
}
</code></pre>
<h1 id="&#x4E8B;&#x52A1;&#x4F20;&#x64AD;&#x673A;&#x5236;">&#x4E8B;&#x52A1;&#x4F20;&#x64AD;&#x673A;&#x5236;</h1>
<p>&#x4E8B;&#x52A1;&#x6700;&#x91CD;&#x8981;&#x7684;&#x4E24;&#x4E2A;&#x7279;&#x6027;&#xFF0C;&#x662F;&#x4E8B;&#x52A1;&#x7684;&#x4F20;&#x64AD;&#x7EA7;&#x522B;&#x548C;&#x6570;&#x636E;&#x9694;&#x79BB;&#x7EA7;&#x522B;&#x3002;&#x4F20;&#x64AD;&#x7EA7;&#x522B;&#x5B9A;&#x4E49;&#x7684;&#x662F;&#x4E8B;&#x52A1;&#x7684;&#x63A7;&#x5236;&#x8303;&#x56F4;&#xFF0C;&#x4E8B;&#x52A1;&#x9694;&#x79BB;&#x7EA7;&#x522B;&#x5B9A;&#x4E49;&#x7684;&#x662F;&#x4E8B;&#x52A1;&#x5728;&#x6570;&#x636E;&#x5E93;&#x8BFB;&#x5199;&#x65B9;&#x9762;&#x7684;&#x63A7;&#x5236;&#x8303;&#x56F4;&#x3002;</p>
<p>&#x4EE5;&#x4E0B;&#x662F;&#x4E8B;&#x52A1;&#x7684;7&#x79CD;&#x4F20;&#x64AD;&#x7EA7;&#x522B;&#xFF1A;</p>
<p>1&#xFF09; <strong><em>\</em>PROPAGATION_REQUIRED**</strong> &#xFF0C;&#x9ED8;&#x8BA4;&#x7684;spring&#x4E8B;&#x52A1;&#x4F20;&#x64AD;&#x7EA7;&#x522B;&#xFF0C;&#x4F7F;&#x7528;&#x8BE5;&#x7EA7;&#x522B;&#x7684;&#x7279;&#x70B9;&#x662F;&#xFF0C;&#x5982;&#x679C;&#x4E0A;&#x4E0B;&#x6587;&#x4E2D;&#x5DF2;&#x7ECF;&#x5B58;&#x5728;&#x4E8B;&#x52A1;&#xFF0C;&#x90A3;&#x4E48;&#x5C31;&#x52A0;&#x5165;&#x5230;&#x4E8B;&#x52A1;&#x4E2D;&#x6267;&#x884C;&#xFF0C;&#x5982;&#x679C;&#x5F53;&#x524D;&#x4E0A;&#x4E0B;&#x6587;&#x4E2D;&#x4E0D;&#x5B58;&#x5728;&#x4E8B;&#x52A1;&#xFF0C;&#x5219;&#x65B0;&#x5EFA;&#x4E8B;&#x52A1;&#x6267;&#x884C;&#x3002;&#x6240;&#x4EE5;&#x8FD9;&#x4E2A;&#x7EA7;&#x522B;&#x901A;&#x5E38;&#x80FD;&#x6EE1;&#x8DB3;&#x5904;&#x7406;&#x5927;&#x591A;&#x6570;&#x7684;&#x4E1A;&#x52A1;&#x573A;&#x666F;&#x3002;</p>
<p>2&#xFF09;<strong><em>\</em>PROPAGATION_SUPPORTS**</strong> &#xFF0C;&#x4ECE;&#x5B57;&#x9762;&#x610F;&#x601D;&#x5C31;&#x77E5;&#x9053;&#xFF0C;supports&#xFF0C;&#x652F;&#x6301;&#xFF0C;&#x8BE5;&#x4F20;&#x64AD;&#x7EA7;&#x522B;&#x7684;&#x7279;&#x70B9;&#x662F;&#xFF0C;&#x5982;&#x679C;&#x4E0A;&#x4E0B;&#x6587;&#x5B58;&#x5728;&#x4E8B;&#x52A1;&#xFF0C;&#x5219;&#x652F;&#x6301;&#x4E8B;&#x52A1;&#x52A0;&#x5165;&#x4E8B;&#x52A1;&#xFF0C;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x4E8B;&#x52A1;&#xFF0C;&#x5219;&#x4F7F;&#x7528;&#x975E;&#x4E8B;&#x52A1;&#x7684;&#x65B9;&#x5F0F;&#x6267;&#x884C;&#x3002;&#x6240;&#x4EE5;&#x8BF4;&#xFF0C;&#x5E76;&#x975E;&#x6240;&#x6709;&#x7684;&#x5305;&#x5728;transactionTemplate.execute&#x4E2D;&#x7684;&#x4EE3;&#x7801;&#x90FD;&#x4F1A;&#x6709;&#x4E8B;&#x52A1;&#x652F;&#x6301;&#x3002;&#x8FD9;&#x4E2A;&#x901A;&#x5E38;&#x662F;&#x7528;&#x6765;&#x5904;&#x7406;&#x90A3;&#x4E9B;&#x5E76;&#x975E;&#x539F;&#x5B50;&#x6027;&#x7684;&#x975E;&#x6838;&#x5FC3;&#x4E1A;&#x52A1;&#x903B;&#x8F91;&#x64CD;&#x4F5C;&#x3002;&#x5E94;&#x7528;&#x573A;&#x666F;&#x8F83;&#x5C11;&#x3002;</p>
<p>3&#xFF09;<strong><em>\</em>PROPAGATION_MANDATORY**</strong> &#xFF0C; &#x8BE5;&#x7EA7;&#x522B;&#x7684;&#x4E8B;&#x52A1;&#x8981;&#x6C42;&#x4E0A;&#x4E0B;&#x6587;&#x4E2D;&#x5FC5;&#x987B;&#x8981;&#x5B58;&#x5728;&#x4E8B;&#x52A1;&#xFF0C;&#x5426;&#x5219;&#x5C31;&#x4F1A;&#x629B;&#x51FA;&#x5F02;&#x5E38;&#xFF01;&#x914D;&#x7F6E;&#x8BE5;&#x65B9;&#x5F0F;&#x7684;&#x4F20;&#x64AD;&#x7EA7;&#x522B;&#x662F;&#x6709;&#x6548;&#x7684;&#x63A7;&#x5236;&#x4E0A;&#x4E0B;&#x6587;&#x8C03;&#x7528;&#x4EE3;&#x7801;&#x9057;&#x6F0F;&#x6DFB;&#x52A0;&#x4E8B;&#x52A1;&#x63A7;&#x5236;&#x7684;&#x4FDD;&#x8BC1;&#x624B;&#x6BB5;&#x3002;&#x6BD4;&#x5982;&#x4E00;&#x6BB5;&#x4EE3;&#x7801;&#x4E0D;&#x80FD;&#x5355;&#x72EC;&#x88AB;&#x8C03;&#x7528;&#x6267;&#x884C;&#xFF0C;&#x4F46;&#x662F;&#x4E00;&#x65E6;&#x88AB;&#x8C03;&#x7528;&#xFF0C;&#x5C31;&#x5FC5;&#x987B;&#x6709;&#x4E8B;&#x52A1;&#x5305;&#x542B;&#x7684;&#x60C5;&#x51B5;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x8FD9;&#x4E2A;&#x4F20;&#x64AD;&#x7EA7;&#x522B;&#x3002;</p>
<p>4&#xFF09;<strong><em>\</em>PROPAGATION_REQUIRES_NEW**</strong> &#xFF0C;&#x4ECE;&#x5B57;&#x9762;&#x5373;&#x53EF;&#x77E5;&#x9053;&#xFF0C;new&#xFF0C;&#x6BCF;&#x6B21;&#x90FD;&#x8981;&#x4E00;&#x4E2A;&#x65B0;&#x4E8B;&#x52A1;&#xFF0C;&#x8BE5;&#x4F20;&#x64AD;&#x7EA7;&#x522B;&#x7684;&#x7279;&#x70B9;&#x662F;&#xFF0C;&#x6BCF;&#x6B21;&#x90FD;&#x4F1A;&#x65B0;&#x5EFA;&#x4E00;&#x4E2A;&#x4E8B;&#x52A1;&#xFF0C;&#x5E76;&#x4E14;&#x540C;&#x65F6;&#x5C06;&#x4E0A;&#x4E0B;&#x6587;&#x4E2D;&#x7684;&#x4E8B;&#x52A1;&#x6302;&#x8D77;&#xFF0C;&#x6267;&#x884C;&#x5F53;&#x524D;&#x65B0;&#x5EFA;&#x4E8B;&#x52A1;&#x5B8C;&#x6210;&#x4EE5;&#x540E;&#xFF0C;&#x4E0A;&#x4E0B;&#x6587;&#x4E8B;&#x52A1;&#x6062;&#x590D;&#x518D;&#x6267;&#x884C;&#x3002;</p>
<p>&#x8FD9;&#x662F;&#x4E00;&#x4E2A;&#x5F88;&#x6709;&#x7528;&#x7684;&#x4F20;&#x64AD;&#x7EA7;&#x522B;&#xFF0C;&#x4E3E;&#x4E00;&#x4E2A;&#x5E94;&#x7528;&#x573A;&#x666F;&#xFF1A;&#x73B0;&#x5728;&#x6709;&#x4E00;&#x4E2A;&#x53D1;&#x9001;100&#x4E2A;&#x7EA2;&#x5305;&#x7684;&#x64CD;&#x4F5C;&#xFF0C;&#x5728;&#x53D1;&#x9001;&#x4E4B;&#x524D;&#xFF0C;&#x8981;&#x505A;&#x4E00;&#x4E9B;&#x7CFB;&#x7EDF;&#x7684;&#x521D;&#x59CB;&#x5316;&#x3001;&#x9A8C;&#x8BC1;&#x3001;&#x6570;&#x636E;&#x8BB0;&#x5F55;&#x64CD;&#x4F5C;&#xFF0C;&#x7136;&#x540E;&#x53D1;&#x9001;100&#x5C01;&#x7EA2;&#x5305;&#xFF0C;&#x7136;&#x540E;&#x518D;&#x8BB0;&#x5F55;&#x53D1;&#x9001;&#x65E5;&#x5FD7;&#xFF0C;&#x53D1;&#x9001;&#x65E5;&#x5FD7;&#x8981;&#x6C42;100%&#x7684;&#x51C6;&#x786E;&#xFF0C;&#x5982;&#x679C;&#x65E5;&#x5FD7;&#x4E0D;&#x51C6;&#x786E;&#xFF0C;&#x90A3;&#x4E48;&#x6574;&#x4E2A;&#x7236;&#x4E8B;&#x52A1;&#x903B;&#x8F91;&#x9700;&#x8981;&#x56DE;&#x6EDA;&#x3002;
&#x600E;&#x4E48;&#x5904;&#x7406;&#x6574;&#x4E2A;&#x4E1A;&#x52A1;&#x9700;&#x6C42;&#x5462;&#xFF1F;&#x5C31;&#x662F;&#x901A;&#x8FC7;&#x8FD9;&#x4E2A;PROPAGATION_REQUIRES_NEW &#x7EA7;&#x522B;&#x7684;&#x4E8B;&#x52A1;&#x4F20;&#x64AD;&#x63A7;&#x5236;&#x5C31;&#x53EF;&#x4EE5;&#x5B8C;&#x6210;&#x3002;&#x53D1;&#x9001;&#x7EA2;&#x5305;&#x7684;&#x5B50;&#x4E8B;&#x52A1;&#x4E0D;&#x4F1A;&#x76F4;&#x63A5;&#x5F71;&#x54CD;&#x5230;&#x7236;&#x4E8B;&#x52A1;&#x7684;&#x63D0;&#x4EA4;&#x548C;&#x56DE;&#x6EDA;&#x3002;</p>
<p>5&#xFF09;<strong><em>\</em>PROPAGATION_NOT_SUPPORTED**</strong> &#xFF0C;&#x8FD9;&#x4E2A;&#x4E5F;&#x53EF;&#x4EE5;&#x4ECE;&#x5B57;&#x9762;&#x5F97;&#x77E5;&#xFF0C;not supported &#xFF0C;&#x4E0D;&#x652F;&#x6301;&#xFF0C;&#x5F53;&#x524D;&#x7EA7;&#x522B;&#x7684;&#x7279;&#x70B9;&#x5C31;&#x662F;&#x4E0A;&#x4E0B;&#x6587;&#x4E2D;&#x5B58;&#x5728;&#x4E8B;&#x52A1;&#xFF0C;&#x5219;&#x6302;&#x8D77;&#x4E8B;&#x52A1;&#xFF0C;&#x6267;&#x884C;&#x5F53;&#x524D;&#x903B;&#x8F91;&#xFF0C;&#x7ED3;&#x675F;&#x540E;&#x6062;&#x590D;&#x4E0A;&#x4E0B;&#x6587;&#x7684;&#x4E8B;&#x52A1;&#x3002;</p>
<p>&#x8FD9;&#x4E2A;&#x7EA7;&#x522B;&#x6709;&#x4EC0;&#x4E48;&#x597D;&#x5904;&#xFF1F;&#x53EF;&#x4EE5;&#x5E2E;&#x52A9;&#x4F60;&#x5C06;&#x4E8B;&#x52A1;&#x6781;&#x53EF;&#x80FD;&#x7684;&#x7F29;&#x5C0F;&#x3002;&#x6211;&#x4EEC;&#x77E5;&#x9053;&#x4E00;&#x4E2A;&#x4E8B;&#x52A1;&#x8D8A;&#x5927;&#xFF0C;&#x5B83;&#x5B58;&#x5728;&#x7684;&#x98CE;&#x9669;&#x4E5F;&#x5C31;&#x8D8A;&#x591A;&#x3002;&#x6240;&#x4EE5;&#x5728;&#x5904;&#x7406;&#x4E8B;&#x52A1;&#x7684;&#x8FC7;&#x7A0B;&#x4E2D;&#xFF0C;&#x8981;&#x4FDD;&#x8BC1;&#x5C3D;&#x53EF;&#x80FD;&#x7684;&#x7F29;&#x5C0F;&#x8303;&#x56F4;&#x3002;&#x6BD4;&#x5982;&#x4E00;&#x6BB5;&#x4EE3;&#x7801;&#xFF0C;&#x662F;&#x6BCF;&#x6B21;&#x903B;&#x8F91;&#x64CD;&#x4F5C;&#x90FD;&#x5FC5;&#x987B;&#x8C03;&#x7528;&#x7684;&#xFF0C;&#x6BD4;&#x5982;&#x5FAA;&#x73AF;1000&#x6B21;&#x7684;&#x67D0;&#x4E2A;&#x975E;&#x6838;&#x5FC3;&#x4E1A;&#x52A1;&#x903B;&#x8F91;&#x64CD;&#x4F5C;&#x3002;&#x8FD9;&#x6837;&#x7684;&#x4EE3;&#x7801;&#x5982;&#x679C;&#x5305;&#x5728;&#x4E8B;&#x52A1;&#x4E2D;&#xFF0C;&#x52BF;&#x5FC5;&#x9020;&#x6210;&#x4E8B;&#x52A1;&#x592A;&#x5927;&#xFF0C;&#x5BFC;&#x81F4;&#x51FA;&#x73B0;&#x4E00;&#x4E9B;&#x96BE;&#x4EE5;&#x8003;&#x8651;&#x5468;&#x5168;&#x7684;&#x5F02;&#x5E38;&#x60C5;&#x51B5;&#x3002;&#x6240;&#x4EE5;&#x8FD9;&#x4E2A;&#x4E8B;&#x52A1;&#x8FD9;&#x4E2A;&#x7EA7;&#x522B;&#x7684;&#x4F20;&#x64AD;&#x7EA7;&#x522B;&#x5C31;&#x6D3E;&#x4E0A;&#x7528;&#x573A;&#x4E86;&#x3002;&#x7528;&#x5F53;&#x524D;&#x7EA7;&#x522B;&#x7684;&#x4E8B;&#x52A1;&#x6A21;&#x677F;&#x62B1;&#x8D77;&#x6765;&#x5C31;&#x53EF;&#x4EE5;&#x4E86;&#x3002;</p>
<p>6&#xFF09;<strong><em>\</em>PROPAGATION_NEVER**</strong> &#xFF0C;&#x8BE5;&#x4E8B;&#x52A1;&#x66F4;&#x4E25;&#x683C;&#xFF0C;&#x4E0A;&#x9762;&#x4E00;&#x4E2A;&#x4E8B;&#x52A1;&#x4F20;&#x64AD;&#x7EA7;&#x522B;&#x53EA;&#x662F;&#x4E0D;&#x652F;&#x6301;&#x800C;&#x5DF2;&#xFF0C;&#x6709;&#x4E8B;&#x52A1;&#x5C31;&#x6302;&#x8D77;&#xFF0C;&#x800C;PROPAGATION_NEVER&#x4F20;&#x64AD;&#x7EA7;&#x522B;&#x8981;&#x6C42;&#x4E0A;&#x4E0B;&#x6587;&#x4E2D;&#x4E0D;&#x80FD;&#x5B58;&#x5728;&#x4E8B;&#x52A1;&#xFF0C;&#x4E00;&#x65E6;&#x6709;&#x4E8B;&#x52A1;&#xFF0C;&#x5C31;&#x629B;&#x51FA;runtime&#x5F02;&#x5E38;&#xFF0C;&#x5F3A;&#x5236;&#x505C;&#x6B62;&#x6267;&#x884C;&#xFF01;&#x8FD9;&#x4E2A;&#x7EA7;&#x522B;&#x4E0A;&#x8F88;&#x5B50;&#x8DDF;&#x4E8B;&#x52A1;&#x6709;&#x4EC7;&#x3002;</p>
<p>7&#xFF09;<strong><em>\</em>PROPAGATION_NESTED**</strong> &#xFF0C;&#x5B57;&#x9762;&#x4E5F;&#x53EF;&#x77E5;&#x9053;&#xFF0C;nested&#xFF0C;&#x5D4C;&#x5957;&#x7EA7;&#x522B;&#x4E8B;&#x52A1;&#x3002;&#x8BE5;&#x4F20;&#x64AD;&#x7EA7;&#x522B;&#x7279;&#x5F81;&#x662F;&#xFF0C;&#x5982;&#x679C;&#x4E0A;&#x4E0B;&#x6587;&#x4E2D;&#x5B58;&#x5728;&#x4E8B;&#x52A1;&#xFF0C;&#x5219;&#x5D4C;&#x5957;&#x4E8B;&#x52A1;&#x6267;&#x884C;&#xFF0C;&#x5982;&#x679C;&#x4E0D;&#x5B58;&#x5728;&#x4E8B;&#x52A1;&#xFF0C;&#x5219;&#x65B0;&#x5EFA;&#x4E8B;&#x52A1;&#x3002;</p>
<pre><code class="lang-java"><span class="hljs-meta">@Transactional</span>(propagation=Propagation.REQUIRED,rollbackFor=Exception.class)
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Spring","level":"2.4.1","depth":2,"next":{"title":"SpringMVC","level":"2.5","depth":1,"ref":"","articles":[{"title":"SpringMVC","level":"2.5.1","depth":2,"path":"books/springMVC/springMVC.md","ref":"books/springMVC/springMVC.md","articles":[]}]},"previous":{"title":"Spring","level":"2.4","depth":1,"ref":"","articles":[{"title":"Spring","level":"2.4.1","depth":2,"path":"books/spring/spring.md","ref":"books/spring/spring.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["search-pro","code","back-to-top-button","theme-comscore","intopic-toc","flexible-alerts","expandable-chapters"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"intopic-toc":{"selector":".markdown-section h1, .markdown-section h2, .markdown-section h3, .markdown-section h4, .markdown-section h5, .markdown-section h6","mode":"nested","maxDepth":6,"isCollapsed":true,"isScrollspyActive":true,"visible":true,"label":"In this article"},"search-pro":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"code":{"copyButtons":true},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"theme-comscore":{},"back-to-top-button":{},"flexible-alerts":{"style":"callout","note":{"label":"Note","icon":"fa fa-info-circle","className":"info"},"tip":{"label":"Tip","icon":"fa fa-lightbulb-o","className":"tip"},"warning":{"label":"Warning","icon":"fa fa-exclamation-triangle","className":"warning"},"danger":{"label":"Attention","icon":"fa fa-ban","className":"danger"}},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{}},"theme":"default","author":"作者","lang":"zh-cn","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"isbn":"图书编号","variables":{},"title":"书名","gitbook":"*","description":"描述"},"file":{"path":"books/spring/spring.md","mtime":"2022-12-08T11:19:20.115Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2023-03-01T12:24:55.135Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-intopic-toc/anchor.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-intopic-toc/gumshoe.polyfills.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-intopic-toc/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-flexible-alerts/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

